<%@ page import="service.ProductService" %>
<%@ page import="service.Impl.ProductServiceImpl" %>
<%@ page import="java.util.List" %>
<%@ page import="entity.Product" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 陪你度过漫长岁月
  Date: 2022/8/10
  Time: 10:33
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>$Title$</title>
  </head>
  <body>
    <table border="1">
      <tr>
        <td>编号</td>
        <td>名称</td>
        <td>描述</td>
        <td>价格</td>
        <td>状态</td>
        <td>操作</td>
      </tr>
      <%
        request.setCharacterEncoding("UTF-8");
        ProductService productService = new ProductServiceImpl();
        List<Product> list = productService.listProduct();
        request.setAttribute("list",list);
      %>
      <c:forEach var="list" items="${list}">
        <tr>
          <td>${list.id}</td>
          <td>${list.name}</td>
          <td>${list.desc}</td>
          <td>${list.price}</td>
          <td>${list.flag}</td>
          <td>
            <a href="#" >修改</a>
            <a href="#" onclick="Delete(${list.id})">删除</a>
          </td>
        </tr>
      </c:forEach>
    </table>
    <a href="insert.jsp">新增元宇宙商品</a>
    <script src="jQuery3.6.0.js"></script>
    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
    <script>
      function Delete(id){
        var u = confirm("确定要修改此商品状态吗？")
        if(u==true){
          $.getJSON("${pageContext.request.contextPath}/DeleteServlet",{'id':id},function (data){
            if(data.rows="1"){
              alert("修改成功");
              location.href="index.jsp"
            }else{
              alert("修改失败");
            }
          })

        }
      }
    </script>
  </body>
</html>
